package com.yys.huarongdao;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.print.PrinterId;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.yys.huarongdao.application.MyApplication;
import com.yys.huarongdao.utils.BgmUtil;

public class BgmActivity extends AppCompatActivity {

    private RadioGroup rg_bgm;
    private RadioButton rbut_openBgm;
    private RadioButton rbut_closeBgm;
    private Button but_submit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getSupportActionBar()!=null){
            getSupportActionBar().hide();
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_bgm);
        bindView();
    }

    private void bindView(){
        rg_bgm=findViewById(R.id.rg_bgm);
        rbut_openBgm=findViewById(R.id.rbut_openBgm);
        rbut_closeBgm=findViewById(R.id.rbut_closeBgm);
        but_submit=findViewById(R.id.but_submit);

        setOnCheckedChangeListener(rg_bgm);
        setDefaultChecked(rg_bgm);
        but_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public void setOnCheckedChangeListener(RadioGroup rg){
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rbut_openBgm:
                        Toast.makeText(BgmActivity.this,"打开背景音乐",Toast.LENGTH_SHORT).show();
                        BgmUtil.openBgm(BgmActivity.this);
                        break;
                    case R.id.rbut_closeBgm:
                        Toast.makeText(BgmActivity.this,"关闭背景音乐",Toast.LENGTH_SHORT).show();
                        BgmUtil.closeBgm(BgmActivity.this);
                        break;
                }
            }
        });
    }

    public void setDefaultChecked(RadioGroup rg){
        if(BgmUtil.BgmPlaying()||BgmUtil.getBgmStatus()==BgmUtil.STATUS_BGM_PAUSE){
//            Log.d("BGM","BGMActivity，onCreate,默认选择开启"+BgmUtil.BgmPlaying());
            rbut_openBgm.setChecked(true);
        }else {
//            Log.d("BGM","BGMActivity，onCreate,默认选择关闭"+BgmUtil.BgmPlaying());
            rbut_closeBgm.setChecked(true);
        }
    }

}
